/** Frame **/
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
var FFextraHeight=getFFVersion>=0.1? 16 : 0;
function dyniframesize(iframename) 
{
	var pTar = null;
	if (document.getElementById)
	{
		pTar = document.getElementById(iframename);
	}
	else
	{
		eval('pTar = ' + iframename + ';');
	}
	if (pTar && !window.opera)
	{
		//begin resizing iframe
		pTar.style.display="block";
		if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight)
		{
			//ns6 syntax
			pTar.height = pTar.contentDocument.body.offsetHeight+FFextraHeight + 1;
		}
		else if (pTar.Document && pTar.Document.body.scrollHeight)
		{
			//ie5+ syntax
			pTar.height = pTar.Document.body.scrollHeight + 1;
		}
	}
}

/** Common Lib**/
function getElement(id) {
	return document.getElementById(id);
}

function createElement(type) {
	return document.createElement(type);
}

function removeElement(element) {
	try {
		if (element) {
			element.parentNode.removeChild(element);
		}
	}
	catch (e) {
	}
}

function hideElement(element) {
	if (element) {
		element.style.display = "none";
	}
}

function hideElementV(element) {
	if (element) {
		element.style.visibility = "hidden";
		element.style.display = "";
	}
}

function showElement(element) {
	if (element) {
		element.style.display = "";
		element.style.visibility = "";
	}
}

function clearElement(element) {
	for (var i in element) {
		try {
			
			element[i] = null;
		}
		catch (e) {
			continue;
		}
	}
}

function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return([myWidth,myHeight]);
}

function GetOffsetPos(element) {
	var flag = element.tagName.toUpperCase() == "INPUT" ? true : false;
	var posTop = 0, posLeft = 0;
	do {
		posTop += element.offsetTop || 0;
		posLeft += element.offsetLeft || 0;
		element = element.offsetParent;
	} while (element);
    return [posLeft, posTop];
}

function hideSelects(zIndexNow) {
	if (navigator.appVersion.indexOf("MSIE 6.0") != -1) {
		var selects = document.getElementsByTagName("select");
		var length = selects.length;
		for (var i = 0; i < length; i++) {
			if (selects[i].zIndexNow != zIndexNow && selects[i].style.visibility != "hidden") {
				selects[i].style.visibility = "hidden";
				selects[i].zIndexNow = zIndexNow;
			}
		}
	}
}

function showSelects(zIndexNow) {
	if (navigator.appVersion.indexOf("MSIE 6.0") != -1) {
		var selects = document.getElementsByTagName("select");
		var length = selects.length;
		for (var i = 0; i < length; i++) {
			if (selects[i].zIndexNow == zIndexNow) {
				selects[i].style.visibility = "";
				selects[i].zIndexNow = -1;
			}
		}
	}
}

var LoaderScript = function () {
	this.elementContainer = null;
	this.init = function (stringContainerId) {
		if (stringContainerId) {
			this.elementContainer = document.getElementById(stringContainerId);
		}
		else {
			this.elementContainer = document.createElement("div");
			this.elementContainer.style.display = "none";
			document.body.appendChild(this.elementContainer);
		}
	};
	this.load = function (src, callback, valueCallback) {
		var elementLoader = document.createElement("script");
		elementLoader.type = "text/javascript";
		elementLoader.language = "javascript";
		elementLoader.charset = "utf-8";
		elementLoader.src = src;
		elementLoader.valueCallback = valueCallback;
		elementLoader[document.all ? "onreadystatechange" : "onload"] = this.unload;
		elementLoader.callback = callback;
		this.elementContainer.appendChild(elementLoader);
	};
	this.unload = function () {
		if (document.all) {
			if (this.readyState != "loaded" && this.readyState != "complete") {
				return;
			}
		}
		if (this.callback) {
			this.callback(this.valueCallback);
		}
		this.callback = null;
		this[document.all ? "onreadystatechange" : "onload"] = null;
		this.parentNode.removeChild(this);
	};
};

var LoaderAjax = function () {
	this.createXMLHttpObject = function () {
		try {
			return new XMLHttpRequest();
		}
		catch (e) {
		}
		try {
			return new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch (e) {
		}
		try {
			return new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e) {
		}
		return null;
	};
	this.load = function (url, callback, content) {
		var xmlhttp = this.createXMLHttpObject();
		if (xmlhttp != null) {
			xmlhttp.open("post", url, true);
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			xmlhttp.setRequestHeader("Content-Type","text/xml");
			xmlhttp.setRequestHeader("Content-Type","utf-8");
			xmlhttp.onreadystatechange = function () {
				if (xmlhttp.readyState == 4) {
					if (xmlhttp.status == 200) {
						var text = xmlhttp.responseText;
						xmlhttp.abort();
						xmlhttp = null;
						callback(text);
					}
				}
			};
			content = content == undefined ? null : content;
			xmlhttp.send(content);
		}
	};
};

var Model = function (stringType, stringContainerId) {
	this.getRandomString = function () {
		var date = new Date();
		return date.getTime();
	};
	this.stringType = stringType.toLowerCase();
	this.responseText = null;
	this.booleanReturnForced = false;
	switch (this.stringType) {
		case "ajax":
			this.loader = new LoaderAjax();
			break;
		case "script":
			this.loader = new LoaderScript();
			this.loader.init(stringContainerId);
			break;
	}
	this.stringUrl = "";
	this.stringMark = "@RANDOM@";
	this.callback = function (responseText) {
		var model = arguments.callee.model;
		switch (model.stringType) {
			case "ajax":
				if ((model.responseText != responseText || model.booleanReturnForced) && responseText != "") {
					model.responseText = responseText;
					model.processData.model = model;
					model.processData(responseText);
					model.updateView();
				}
				break;
			case "script":
				model.processData(responseText);
				model.updateView(responseText);
				break;
		}
	};
	this.callback.model = this;
	this.processData = function () {};
	this.updateView = function () {};
	this.stringContent = null;
	this.intThread = -1;
	this.intInterval = 5000;
	this.start = function () {
		this.stop();
		this.load();
		this.intThread = setInterval(this.load, this.intInterval);
	};
	this.stop = function () {
		if (this.intThread != -1) {
			clearInterval(this.intThread);
		}
		this.intThread = -1;
	};
	this.arrayUrl = [];
	this.loadScriptUrl = function () {
		var model = arguments.callee.model;
		if (model.arrayUrl.length > 0) {
			var stringUrl = model.arrayUrl.shift();
			model.loader.load(stringUrl.replace(model.stringMark, model.getRandomString()), model.callback, stringUrl);
		}
	};
	this.loadScriptUrl.model = this;
	this.load = function () {
		var model = arguments.callee.model;
		switch (model.stringType) {
			case "ajax":
				model.loader.load(model.stringUrl.replace(model.stringMark, model.getRandomString()), model.callback, model.stringContent);
				break;
			case "script":
				if (model.stringUrl.constructor == Array) {
					model.arrayUrl = [];
					for (var i = 0; i < model.stringUrl.length; i++) {
						model.arrayUrl.push(model.stringUrl[i]);
						setTimeout(model.loadScriptUrl, i * 5000);
					}
				}
				else if (model.stringUrl != "") {
					model.loader.load(model.stringUrl.replace(model.stringMark, model.getRandomString()), model.callback, model.stringUrl);
				}
				break;
		}
	};
	this.load.model = this;
};

var DragAble = function (dragable,handler) {
	this.iDiffX = 0;
	this.iDiffY = 0;
	this.oDragable = dragable;
	this.oHandler = handler;
	
	this.mouseDown = function(){
		document.body.onselectstart = function () {return false;};
		document.body.style.userSelect = "none";
		document.body.style.MozUserSelect = "none";
		var object = arguments.callee.object;
		var event = arguments[0] || window.event;
		object.iDiffX = event.clientX - object.oDragable.offsetLeft;
		object.iDiffY = event.clientY - object.oDragable.offsetTop;
		document.body.onmousemove = object.mouseMove;
		document.body.onmouseup = object.mouseUp;
		object.oHandler.style.cursor = "move";
	};
	this.mouseDown.object = this;
	
	this.oHandler.onmousedown = this.mouseDown;
	
	this.mouseMove = function() {
		var object = arguments.callee.object;
		var event = arguments[0] || window.event;
		var wWidth = getWindowSize()[0];
		if ((event.clientX - object.iDiffX) >= 0 && (event.clientX - object.iDiffX + object.oDragable.clientWidth) <= wWidth - 20){
			object.oDragable.style.left = event.clientX - object.iDiffX + "px";
		}
		else {
			if ((event.clientX - object.iDiffX) < 0){
				object.oDragable.style.left = 0 + "px";
			}
			else {
				object.oDragable.style.left = wWidth - object.oDragable.clientWidth - 20 + "px";
			}
		}
		//obj.style.left = tempLeft + "px";
		if ((event.clientY - object.iDiffY) >= 0){
			object.oDragable.style.top = event.clientY - object.iDiffY + "px";
		}
		else {
			object.oDragable.style.top = 0 + "px";
		}
		
	};
	this.mouseMove.object = this;
	
	this.mouseUp = function() {
		var object = arguments.callee.object;
		document.body.onselectstart = "";
		document.body.style.userSelect = "";
		document.body.style.MozUserSelect = "";
		document.body.onmousemove = "";
		document.body.onmouseup = "";
		object.oHandler.style.cursor = "";
	};
	this.mouseUp.object = this;
};

function __JavascriptLoader(url, fnCallback)
{
    var mod = new Model("script", "loaderScriptContainer");
    mod.stringUrl = url;
    var _fnCall_ = fnCallback;
    if( typeof(_fnCall_) == 'function' && arguments.length > 2 )
    {
        var argus = Array.prototype.slice.call(arguments, 2);
        var fn = (function()
        {
            _fnCall_.apply(null, argus);
        });
        
        mod.processData = function(text)
        {
            try
            {
                fn();
            }
            catch(e)
            {}
        };      
    }
    else
    {
        mod.processData = function(text)
        {
            try
            {
                fnCallback();
            }
            catch(e)
            {}
        };
    }

    mod.load();
}